package com.ruoyi.web.controller.base;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BBank;
import com.ruoyi.base.service.IBBankService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题库Controller
 * 
 * @author ruoyi
 * @date 2024-03-24
 */
@RestController
@RequestMapping("/base/bank")
public class BBankController extends BaseController
{
    @Autowired
    private IBBankService bBankService;

    /**
     * 查询题库列表
     */
    @PreAuthorize("@ss.hasPermi('base:bank:list')")
    @GetMapping("/list")
    public TableDataInfo list(BBank bBank)
    {
        startPage();
        List<BBank> list = bBankService.selectBBankList(bBank);
        return getDataTable(list);
    }

    /**
     * 导出题库列表
     */
    @PreAuthorize("@ss.hasPermi('base:bank:export')")
    @Log(title = "题库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BBank bBank)
    {
        List<BBank> list = bBankService.selectBBankList(bBank);
        ExcelUtil<BBank> util = new ExcelUtil<BBank>(BBank.class);
        util.exportExcel(response, list, "题库数据");
    }

    /**
     * 获取题库详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:bank:query')")
    @GetMapping(value = "/{bankId}")
    public AjaxResult getInfo(@PathVariable("bankId") Long bankId)
    {
        return success(bBankService.selectBBankByBankId(bankId));
    }

    /**
     * 新增题库
     */
    @PreAuthorize("@ss.hasPermi('base:bank:add')")
    @Log(title = "题库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BBank bBank)
    {
        return toAjax(bBankService.insertBBank(bBank));
    }

    /**
     * 修改题库
     */
    @PreAuthorize("@ss.hasPermi('base:bank:edit')")
    @Log(title = "题库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BBank bBank)
    {
        return toAjax(bBankService.updateBBank(bBank));
    }

    /**
     * 删除题库
     */
    @PreAuthorize("@ss.hasPermi('base:bank:remove')")
    @Log(title = "题库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bankIds}")
    public AjaxResult remove(@PathVariable Long[] bankIds)
    {
        return toAjax(bBankService.deleteBBankByBankIds(bankIds));
    }
}
